package florestapokemon;

import java.util.Random;

public class Position {

	public int x;
	public int y;

	public Position() {
		x = 0;
		y = 0;
	}

	public Position(int x, int y) {
		this.x = x;
		this.y = y;
	}

	/*public void move(int x, int y) {
		this.x += x;
		this.y += y;
	}*/

	public Position nextStep(Position pos) {

		int xPos = 0;
		int yPos = 0;

		if (x < pos.x)
			xPos = 1;
		else if (x > pos.x)
			xPos = -1;

		if (y < pos.y)
			yPos = 1;
		else if (y < pos.y)
			yPos = -1;

		if (xPos != 0 && yPos != 0) {
			if(new Random().nextBoolean()) {
				return new Position(x + xPos, y);
			} else {
				return new Position(x, y + yPos);
			}
		} else
			return new Position(xPos, yPos);
	}

	public int hashCode() {
		return x + y;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;

		Position posObj = (Position)(obj);
		if (posObj == null)
			return false;

		return this.x == posObj.x && this.y == posObj.y;
	}
}
